package com.hkfn.rfb.common.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.hkfn.rfb.R;
import com.hkfn.rfb.common.bean.BaseModel;
import com.hkfn.rfb.common.bean.ConstData;
import com.hkfn.rfb.common.fragment.BarFloorFragment;
import com.hkfn.rfb.common.fragment.BaseFragment;
import com.hkfn.rfb.common.fragment.WebFragment;
import com.hkfn.rfb.common.utils.StringUtils;
import com.hkfn.rfb.common.utils.ToastUtils;

public class ShowFragActivity extends BaseActivity{

    private Bundle bundle;

    private View include_head_title;
    public LinearLayout ll_menu;
    public TextView tv_title;

    private BaseModel skipModel;
    private BaseFragment baseFragment;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bundle = getIntent().getExtras();
        if (null != bundle){
            skipModel = (BaseModel) bundle.getSerializable(ConstData.ACTIONMODLE);
        }
        if (null == skipModel){
            ToastUtils.showToast(this, getResources().getString(R.string.data_error));
            finish();
            return;
        }
        setContentView(R.layout.a_common_show_frag);
        setImmerseLayout(findViewById(R.id.include_head_title), findViewById(R.id.rl_head_content));
        initView();
    }

    private void initView() {
        iniHeadTitle();
        initFragment();
    }

    private void iniHeadTitle() {
        include_head_title = findViewById(R.id.include_head_title);
        ll_menu = findViewById(R.id.ll_menu);
        tv_title = findViewById(R.id.tv_title);

        if (StringUtils.isEmpty(skipModel.getActionTitle())){
            tv_title.setText("");
            include_head_title.setVisibility(View.GONE);
        }else {
            tv_title.setText(skipModel.getActionTitle());
            include_head_title.setVisibility(View.VISIBLE);
        }
    }

    private void initFragment() {
        switch (skipModel.getActionValue()){
            case ConstData.BAR_FLOOR:
                baseFragment = new BarFloorFragment();// 左右滑动页面
                break;
            case ConstData.WEB:// 网页
                baseFragment = new WebFragment();
                break;
        }
        baseFragment.setArguments(bundle);
        addFragment(R.id.fl_container, baseFragment);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void doBack(View view) {
        super.doBack(view);;
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
    }

}
